<%@ page language="java"  pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body class="no-skin">
<!-- 以下为内容 -->
	<!--输入区域-->
	<div class="widget-box transparent">
		<div class="widget-header widget-header-small">
			<h4 class="widget-title blue smaller">
				<i class="ace-icon glyphicon glyphicon-file orange"></i>
					修改组织机构
			</h4>
		</div>
		<div class="widget-body">
			<div class="widget-main padding-8">
				<!-- #section:pages/profile.feed -->
				<div id="profile-feed-1" class="profile-feed">
					<form id="orgEditForm" class="form-horizontal" role="form">
						<div class="space-1">
							<input type="hidden" id="orgId" name="orgId" value="${organ.orgId}" />
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">归属</label>
							<div class="col-sm-9">
								<input name="parentCodeStr" type="text" disabled="disabled" id="parentCodeStr" class="col-xs-6" value="${parentName}" />
								<input name="parentCode" type="hidden" id="parentCode" class="col-xs-6" value="${organ.parentCode}" />
							</div>
						</div>

						<div class="space-1"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">机构代码</label>
							<div class="col-sm-9">
									<input type="text" disabled="disabled" id="orgCode" name="orgCode" class="col-xs-6" value="${organ.orgCode}" />
							</div>
						</div>

						<div class="space-1"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">机构名称</label>
							<div class="col-sm-9">
								<input name="orgName" type="text" id="orgName" maxlength="100" class="col-xs-6" value="${organ.orgName}" />
							</div>
						</div>

						<div class="space-1"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">机构简称</label>
							<div class="col-sm-9">
								<input name="simpleName" type="text" id="simpleName" maxlength="20" class="col-xs-6" value="${organ.simpleName}" />
							</div>
						</div>

						<div class="space-1"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">描述</label>
							<div class="col-sm-9">
							  <textarea name="remark" rows="5" class="col-xs-6 " id="remark">${organ.remark}</textarea>
							</div>
						</div>

					   <div class="space-1"></div>
					   <div class="form-group">
						   <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 状态 </label>
						   <div class="col-sm-9">
							   <input type="radio" name="statusRadio" value="1" ${organ.status==1?"checked":""} />有效 &nbsp;&nbsp;
							   <input type="radio" name="statusRadio" value="0" ${organ.status==0?"checked":""} />无效
							   <input type="hidden" id="status" name="status" />
						   </div>
					   </div>
					</form>
				</div>
				<div class="col-xs-12" style="text-align:center"><!-- 按钮行-->
					<div class="clearfix form-actions" style="">

						<button class="btn btn-info" type="button" id="subBtn" onclick="submitOrgEditForm();">
							<i class="ace-icon fa fa-save bigger-110"></i>
								保 存
						</button>
						<button class="btn" type="button" id="canBtn" onclick="toBack();">
							<i class="ace-icon fa fa-undo bigger-110"></i>
								返 回
						</button>
					</div>
				</div>
			</div>
		</div>
	</div>
		<!-- basic scripts -->
	<link rel="stylesheet" href="${resRoot}/plugin/zTree_v3/css/demo.css" type="text/css">
	<link rel="stylesheet" href="${resRoot}/plugin/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script src="${resRoot}/plugin/ace-v1.3/assets/js/jquery.validate.min.js"></script>
	<script src="${resRoot}/plugin/jquery-validation/localization/messages_zh.js"></script>
	<script type="text/javascript">
		//返回
		function toBack() {
			var parentCode = $("#parentCode").val();
			window.location.href = "../../auth/org/toOrgList.htm?parentCode=" + parentCode;
		}

		//提交表单函数
		function submitOrgEditForm() {
			//设置状态值
			var statusVal = $("input[name='statusRadio']:checked").val();
			$("#status").val(statusVal);
			if (validateForm()) {
				//禁用按钮
				$("#subBtn").attr("disabled", true);
				$("#canBtn").attr("disabled", true);
				$.ajax({
					url: contextPath + "/auth/org/editOrg.json",
					type: "post",
					data: $("#orgEditForm").serialize(),
					success: function (data) {
						var msg = eval("(" + data + ")");
						$.Alert(msg.message, '', toOrgList);
					},
					error: function () {
						//$.Alert("服务异常，请稍后尝试！");
						$("#subBtn").removeAttr("disabled");
						$("#canBtn").removeAttr("disabled");
					}
				});
			}
		}

		function toOrgList() {
			parent.location.reload();
		}

		//客户简称验证
		//jQuery.validator.addMethod("dealerShtNameCheck",function(value,element){
		//  var reg = /^[0-9a-zA-Z]+$/;
		// return this.optional(element) || reg.test(value);
		//},"客户简称只能为字母或数字");

		//表单验证函数
		function validateForm() {
			return $("#orgEditForm").validate({
				errorElement: 'span',
				errorClass: 'help-block',
				focusInvalid: false,
				rules: {
					"orgName": {
						required: true
					},
					"simpleName": {
						required: true
					},
					"remark": {
						maxlength: 500
					}
				},

				highlight: function (e) {
					$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
				},

				success: function (e) {
					$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
					$(e).remove();
				},


				errorPlacement: function (error, element) {
					if (element.is(':checkbox') || element.is(':radio')) {
						var controls = element.closest('div[class*="col-"]');
						if (controls.find(':checkbox,:radio').length > 1) controls.append(error);
						else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
					}
					else if (element.is('.select2')) {
						error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
					}
					else if (element.is('.chosen-select')) {
						error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
					}
					else if (element.is('textarea')) {
						error.appendTo(element.parent());
					}
					else if (element.is('input[type=text]')) {
						error.appendTo(element.parent());
					}
					else error.insertAfter(element.parent());
				}
			}).form();
		}
	</script>
</body>
</html>
